package bean;

import java.util.Date;
import java.util.Set;

import javax.jdo.PersistenceManager;

import pmf.PMF;

public class ArticleAdm {
	public Articles createArt(Member mem, String item, int total, int remain,
			int price, Date deadline, Branch b, Category c, ShipStyle ss, int shipFee, String note){
		
		PersistenceManager pm = PMF.get().getPersistenceManager();		
		Articles art = new Articles(null, mem, c, item, price, ss, deadline, b, total, remain, null, shipFee, note);
		pm.makePersistent(art);
		Articles tempArt = new Articles(art.getKey(), art.getCreateUserID(),
				art.getCategory(), art.getArtName(), art.getPrice(), art.getShipWay(), art.getBuyDate(), art.getBranch(),
				art.getTotalAmount(), art.getRemainAmount(), art.getParticipate(), art.getShipFee(), art.getNote());
		pm.close();
		
		return tempArt;
	}
	
	public void addPartToArt(Participate p, long id){
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try{
			Articles a = pm.getObjectById(Articles.class, id);
			Set<Participate> pSet = a.getParticipate();
			pSet.add(p);
		}finally{
			pm.close();
		}			
	}
}
